package cn.yhbk.web.modules.manager.Controller;

import cn.yhbk.web.common.Util.MyUtil;
import cn.yhbk.web.common.api.CommonPage;
import cn.yhbk.web.common.api.CommonResult;
import cn.yhbk.web.modules.manager.Pojo.Entity.TbClass;
import cn.yhbk.web.modules.manager.Pojo.VO.StuWorkOffice.StuWorkOfficeAdd;
import cn.yhbk.web.modules.manager.Pojo.VO.StuWorkOffice.StuWorkOfficeResP;
import cn.yhbk.web.modules.manager.Service.ITbCounsellorService;
import cn.yhbk.web.modules.manager.Service.ITbStuWorkOfficeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 学工办表 前端控制器
 * </p>
 *
 * @author 有何不可
 * @since 2023-08-05
 */
@RestController
@Api(tags = "学工办账号管理接口")
@RequestMapping("/tbStuWorkOffice")
public class TbStuWorkOfficeController {

    @Autowired
    private ITbStuWorkOfficeService officeService;

    @Autowired
    private ITbCounsellorService counsellorService;

    @ApiOperation("添加学工办")
    @PostMapping("/manage")
    public CommonResult addStuWorkOffice(@RequestBody StuWorkOfficeAdd add){

        boolean success = officeService.addStuWorkOffice(add);
        if(success)return CommonResult.success("添加成功!");

        return CommonResult.failed("添加失败!");
    }

    @ApiOperation("获取学工办")
    @GetMapping("/manage/{collegeId}")
    public CommonResult getStuWorkOffice(@RequestParam(name = "currentPage",defaultValue = "1")Long currentPage,
                                             @RequestParam(name="pageSize",defaultValue = "5")Long pageSize,
                                             @PathVariable Long collegeId){
        CommonPage<StuWorkOfficeResP> resPage = officeService.getStuWorkOffice(currentPage, pageSize, collegeId);

        return CommonResult.success(resPage);
    }

    @ApiOperation("删除学工办")
    @DeleteMapping("/manage/{stuWorkOfficeId}")
    public CommonResult deleteStuWorkOffice(@PathVariable Long stuWorkOfficeId){

        boolean success = officeService.removeStuWorkOffice(stuWorkOfficeId);
        if(success)return CommonResult.success("删除成功!");

        return CommonResult.failed("删除失败!");
    }

    //修改status
//    @ApiOperation("修改")
//    @PutMapping("/Common")
//    public CommonResult updateStatus(){
//
//    }


    @ApiOperation("导入学生数据")
    @PostMapping("/importStuInfo")
    public CommonResult<String> importStuInfo(MultipartFile multipartFile){

        Boolean flag = officeService.importStuInfo(multipartFile);

        return CommonResult.success(null, "导入学生数据成功");
    }

    @ApiOperation("获取辅导员管理的班级")
    @GetMapping("/getCounsellorClass/{counsellorId}")
    public CommonResult getCounsellorClass(@PathVariable("counsellorId") Long counsellorId){

        List<TbClass> classes = counsellorService.getMyClass(counsellorId);

        return CommonResult.success(classes);

    }

}
